package com.limm.util;


import java.sql.Connection;
import java.sql.DriverManager;

public class DbUtil {

    private static final String DRIVER = "com.mysql.jdbc.Driver";
    private static final String URL = "jdbc:mysql://localhost:3306/music";
    private static final String USERNAME = "root";
    private static final String PASSWORD = "123456789";
    private static Connection conn = null;

    public static Connection getConn() {

        try {
            Class.forName(DRIVER);
            conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
            if (conn.isClosed()) {
                System.out.println("连接失败！！");
            } else {
                System.out.println("连接成功！！");
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return conn;
    }

    public static void close() {
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {

            }
        }
        System.out.println("关闭连接");
    }

}
